package com.yc.edu.controller;

import com.yc.edu.pojo.User;
import com.yc.edu.pojo.UserVO;
import com.yc.edu.vo.*;
import com.yc.edu.pojo.Result;
import com.yc.edu.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@Slf4j
public class UserController {
    @Resource
    private UserService userService;

    @ApiOperation("通过用户名登录")
    @PostMapping("/login/username")
    public Result loginUserName(@RequestBody UserVO loginUserNameVO) {
        log.info("登录  账号{}  密码{}", loginUserNameVO.getUsername(), loginUserNameVO.getPassword());
        return userService.loginByUsername(loginUserNameVO);
    }

    @ApiOperation("查找某用户")
    @GetMapping("/search/user")
    public Result searchUser(@RequestParam String username) {
        return userService.searchUser(username);
    }
    @PostMapping("/register")
    public Result register(@RequestBody UserVO user){
        System.out.println(user);
        userService.register(user);
        return Result.success();

    }
}
